package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.mapper.UserMapper;
import com.itheima.health.pojo.Menu;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.service.UserService;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public UserVO findUserInfoByUsername(String username) {
        //     根据账号查询 用户对应角色信息
          UserVO  userVO= baseMapper.findUserByUsername(username);
          //  根据用户id  查询对应得角色信息
        List<RoleVO> roleVOList =  baseMapper.findRoleInfoByUserId(userVO.getId());
        //  权限信息
        for (RoleVO roleVO : roleVOList) {
            List<Permission> permissionList = baseMapper.findPermissionInfoByRoleId(roleVO.getId());
            roleVO.setPermissionsList(permissionList);
        }
          userVO.setRoleVOList(roleVOList);
        return userVO;
    }

    @Override
    public List<Menu> queryMenubyUserName(String username) {
        List<Menu> menuList = baseMapper.queryMenubyUserName(username);
        return menuList;
    }
}
